//
//  ChengShiXiangXiJieShao.m
//  MDDNew
//
//  Created by 孙昊坤 on 15/10/30.
//  Copyright © 2015年 heqing. All rights reserved.
//

#import "ChengShiXiangXiJieShao.h"

#import "TYDataManager.h"

// 宽高
#define Kheight [UIScreen mainScreen].bounds.size.height
#define Kwidth [UIScreen mainScreen].bounds.size.width

@interface ChengShiXiangXiJieShao ()

@property (nonatomic, strong) NSMutableArray *dataArray;

@property (nonatomic, strong) UIWebView *webView;

@property (nonatomic, strong) NSURLRequest *request;

@property (nonatomic, strong) UIScrollView *scrollView;

// 计数
@property (nonatomic, assign) NSInteger max;

@property (nonatomic, strong) NSString *url;



@end

@implementation ChengShiXiangXiJieShao

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self jieXi];
    
    
    self.view.backgroundColor = [UIColor whiteColor];
    
}

// 解析
- (void)jieXi
{
    // http://open.qyer.com/qyer/place/city_useful_info?city_id=50&client_id=qyer_ios&client_secret=cd254439208ab658ddf9&count=20&lat=40.0293139698113&lon=116.3373111436184&page=1&track_app_channel=App%2520Store&track_app_version=6.8&track_device_info=iPhone7%2C1&track_deviceid=3D292DEC-1F82-4FE7-9AE7-A1866F5F24E7&track_os=ios%25209.0.2&v=1
    
    NSString *string = [NSString stringWithFormat:@"http://open.qyer.com/qyer/place/city_useful_info?city_id=%@", _ids];
    NSString *string2 = [string stringByAppendingString:@"&client_id=qyer_ios&client_secret=cd254439208ab658ddf9&count=20&lat=40.0293139698113&lon=116.3373111436184&page=1&track_app_channel=App%2520Store&track_app_version=6.8&track_device_info=iPhone7%2C1&track_deviceid=3D292DEC-1F82-4FE7-9AE7-A1866F5F24E7&track_os=ios%25209.0.2&v=1"];
    
    [[TYDataManager shareManager] requestDataWithUrl:string2 block:^(NSData *data){
        
        NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
        
        _dataArray = [dic valueForKey:@"data"];
        
        
        
        
        
        
        
        _max = _dataArray.count;
        
        [self addGunDong];
    }];
}

// 添加web
- (void)addWeb:(NSInteger)i
{
    UIWebView * webView = [[UIWebView alloc] initWithFrame:CGRectMake(i * Kwidth, 64, Kwidth, Kheight)];
    _url = [_dataArray[i]valueForKey:@"appview_url"];
    _request =[NSURLRequest requestWithURL:[NSURL URLWithString:_url]];
    [webView loadRequest:_request];
    [_scrollView addSubview:webView];
}

// 添加滚动视图
- (void)addGunDong
{
    // 创建一个UIScrollView 所有滚动的控件的基类
    _scrollView = [[UIScrollView alloc] initWithFrame:[UIScreen mainScreen].bounds];
    // 设置一些属性
    _scrollView.backgroundColor = [UIColor whiteColor];
    
    // UIScrollView的显示范围 能滑动的范围
    // 左右滑 就改变 宽
    // 上下滑 就改变 高
    _scrollView.contentSize = CGSizeMake(Kwidth * _max, 0);
    
    // 整页滚动 一滚一屏 （默认NO）
    _scrollView.pagingEnabled = YES;
    
    // 边界回弹 (默认YES)
    _scrollView.bounces = YES;
    
    // 水平滚动条是否显示 (默认YES)
    _scrollView.showsHorizontalScrollIndicator = YES;
    // 竖直滚动条是否显示 (默认YES)
    _scrollView.showsVerticalScrollIndicator = YES;
    
    // 重要属性
    // 默认是 0,0  滑动的左上角的点 距离 原点
    _scrollView.contentOffset = CGPointMake(0, 0);
    // Offset 偏移
    
    // 最重要的 就是一堆代理方法
    
    // 控制缩放的属性 （需要控制缩放的代理方法）
    _scrollView.maximumZoomScale = 3.0; // 最大
    _scrollView.minimumZoomScale = 0.5; // 最小
    
    // 注意 设置代理
    _scrollView.delegate = self;
    // 要设置视图缩放 1，（遵守协议）- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView 2，设置代理， 3，设置缩放最大最小值
    
    // 添加释放
    [self.view addSubview:_scrollView];
    
    for (int i = 0; i < _max; i++) {
        [self addWeb:i];
    }
}


// 接口 http://open.qyer.com/qyer/place/city_useful_info?city_id=50&client_id=qyer_ios&client_secret=cd254439208ab658ddf9&count=20&lat=40.0293139698113&lon=116.3373111436184&page=1&track_app_channel=App%2520Store&track_app_version=6.8&track_device_info=iPhone7%2C1&track_deviceid=3D292DEC-1F82-4FE7-9AE7-A1866F5F24E7&track_os=ios%25209.0.2&v=1

@end
